package com.wx.rpc.client.core;

import org.apache.commons.collections4.CollectionUtils;

import java.util.List;

/**
 * @author wx
 * @Description: 负载均衡接口
 * @date 2019/3/9 000915:00
 */
public interface ILoadBanlanceService {

    /**
     * @description: 获取服务地址
     * @author: wx
     * @date: 2019/3/9 0009
     * @param serviceNodes
     * @return: java.lang.String
     */
    default String selectHost(List<String> serviceNodes) {
        if (CollectionUtils.isEmpty(serviceNodes)) {
            return "";
        }
        if (serviceNodes.size() == 1) {
            return serviceNodes.get(0);
        }
        return doSelect(serviceNodes);
    }

    /**
     * @description: 负载均衡获取服务
     * @author: wx
     * @date: 2019/3/9 0009
     * @param serviceNodes
     * @return: java.lang.String
     */
    String doSelect(List<String> serviceNodes);


}
